package cn.csc.framework.jzb.config;

import cn.csc.framework.jzb.core.JzbClient;
import com.pingan.openbank.api.sdk.client.ApiClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.util.Properties;

/**
 * 见证宝接口的自动配置类
 * @author liuchuang
 * @version 1.0
 * @date 2023/3/9 17:01
 * @modify
 */
@AutoConfiguration
@EnableConfigurationProperties(JzbProperties.class)
public class JzbAutoConfiguration {

    @Autowired
    private JzbProperties jzbProperties;

    @Bean
    public ApiClient apiClient(){
        Properties props = new Properties();

        props.setProperty("appPrivateKey",jzbProperties.getAppPrivateKey());
        props.setProperty("publicKey", jzbProperties.getPublicKey());
        props.setProperty("appId", jzbProperties.getAppId());
        props.setProperty("baseUrl", jzbProperties.getBaseUrl());
        props.setProperty("appSecret", jzbProperties.getAppSecret());
        props.setProperty("fileUploadUrl", jzbProperties.getFileUploadUrl());
        props.setProperty("fileDownLoadUrl", jzbProperties.getFileDownLoadUrl());

        return ApiClient.getInstance(props);
    }

    @Bean
    public JzbClient jzbClient(ApiClient apiClient, JzbProperties jzbProperties){
        return new JzbClient(apiClient, jzbProperties);
    }

}
